package com.xiashitech.agent.instrumentation.jetty.handler.handle.inst;

import com.google.auto.service.AutoService;
import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule;
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import net.bytebuddy.matcher.ElementMatcher;
import java.util.Arrays;
import java.util.List;
import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasClassesNamed;

@AutoService(InstrumentationModule.class)
public class XSJettyInstrumentationModule extends InstrumentationModule {
    public XSJettyInstrumentationModule() {
        super("XSJetty-Handler");
    }

    @Override
    public ElementMatcher.Junction<ClassLoader> classLoaderMatcher() {
        return hasClassesNamed("javax.servlet.Servlet");
    }

    @Override
    public List<TypeInstrumentation> typeInstrumentations() {
        return Arrays.asList(new XSJettyHandlerInstrumentation("javax.servlet", XSJettyInstrumentationModule.class.getPackage().getName() + ".XSJettyHandlerAdvice"));
    }

    public List<String> getAdditionalHelperClassNames() {
        return Arrays.asList("com.xiashitech.agent.instrumentation.helper.calldepth.XSJettyHandlerCallDepth",
                "com.xiashitech.agent.instrumentation.jetty.handler.handle.inst.common.JettyResponseSetter");
    }
}
